package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoFontType;
import com.muyu.danmo.service.IDanmoFontTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 字体类型Controller
 *
 * @author yangle
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/type")
public class DanmoFontTypeController extends BaseController
{
    @Autowired
    private IDanmoFontTypeService danmoFontTypeService;

    /**
     * 查询字体类型列表
     */
//    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoFontType danmoFontType)
    {
        List<DanmoFontType> list = danmoFontTypeService.selectDanmoFontTypeList(danmoFontType);
        return Result.success(list);
    }

    /**
     * 导出字体类型列表
     */
//    @RequiresPermissions("system:type:export")
    @Log(title = "字体类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoFontType danmoFontType)
    {
        List<DanmoFontType> list = danmoFontTypeService.selectDanmoFontTypeList(danmoFontType);
        ExcelUtil<DanmoFontType> util = new ExcelUtil<DanmoFontType>(DanmoFontType.class);
        util.exportExcel(response, list, "字体类型数据");
    }

    /**
     * 获取字体类型详细信息
     */
//    @RequiresPermissions("system:type:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoFontTypeService.selectDanmoFontTypeById(id));
    }

    /**
     * 新增字体类型
     */
//    @RequiresPermissions("system:type:add")
    @Log(title = "字体类型", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoFontType danmoFontType)
    {
        return toAjax(danmoFontTypeService.insertDanmoFontType(danmoFontType));
    }

    /**
     * 修改字体类型
     */
//    @RequiresPermissions("system:type:edit")
    @Log(title = "字体类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoFontType danmoFontType)
    {
        return toAjax(danmoFontTypeService.updateDanmoFontType(danmoFontType));
    }

    /**
     * 删除字体类型
     */
//    @RequiresPermissions("system:type:remove")
    @Log(title = "字体类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoFontTypeService.deleteDanmoFontTypeByIds(ids));
    }

    /**
     * 根据字体类型查询作者
     */
    @PostMapping("/selectAuthor")
    public Result<List<String>> selectAuthor(@RequestBody DanmoFontType danmoFontType){
       List<String> list = danmoFontTypeService.selectAuthor(danmoFontType);
        return Result.success(list);
    }
}
